$(function(){
	$.ajax({
        type: "get",
        url: "/app/exchangeRate/thenearfuture",
        dataType: "json",
        success: function(r){
        	console.log(r);
        			if(r.code == 0){
        				var list = r.list;
        				var html = "";
        				for (var int = 0; int < list.length; int++) {
        					html += "<option value="+list[int]+">"+list[int]+"</option>"
						}
        				$("#coinName").html(html);
        				$("#coinName2").html(html);
        			}
                }
    });
	$.ajax({
		type: "get",
		url: "/app/exchangeRate/setting",
		dataType: "json",
		success: function(r){
			console.log(r);
			if(r.code == 0){
				var list = r.list;
				for (var int = 0; int < list.length; int++) {
					if(list[int].status == 1){
						$("#coinName").val(list[int].coinName);
						$("#unitPrice").val(list[int].unitPrice);
						$("#count").val(list[int].count);
						$("#mid").val(list[int].id);
						$("#type1").val(list[int].type);
						$("#apiKey1").val(list[int].apiKey);
						$("#secret1").val(list[int].secret);
					}else if(list[int].status == 2){
						$("#coinName2").val(list[int].coinName);
						$("#unitPrice2").val(list[int].unitPrice);
						$("#count2").val(list[int].count);
						$("#oid").val(list[int].id);
						$("#type2").val(list[int].type);
						$("#apiKey2").val(list[int].apiKey);
						$("#secret2").val(list[int].secret);
					}
				}
				
			}
		}
	});
	//买进
	$("[type='button'][name='buy']").click(function(){
		//币种ID
		var mid = $("#mid").val();
		//币种名称
		var name = $('#coinName option:selected') .val();
		//币种单价
		var unitPrice = $("[name='unitPrice']").val();
		unitPrice=parseFloat(unitPrice);//数字接收
		//币种数量
		var count = $("[name='count']").val();
		count=parseFloat(count);//数字接收
		//币种状态
		var type = $('#type1 option:selected').val();
		type = parseInt(type);
		//apiKey
		var apiKey = $("#apiKey1").val();
		//secret
		var secret = $("#secret1").val();
		$.ajax({
	        type: "get",
	        url: "/app/exchangeRate/coinlis",
	        data:{coinName:name,unitPrice:unitPrice,count:count,status:1,type:type,mid:mid,apiKey:apiKey,secret:secret},
	        dataType: "json",
	        success: function(data){
	        	 window.location.reload();
	        }
	    });
	});
	//卖出
	$("[type=button][name=sell]").click(function(){
		//币种ID
		var mid = $("#oid").val();
		//币种名称
		var name = $('#coinName2 option:selected') .val();
		//币种单价
		var unitPrice = $("[name='unitPrice2']").val();
		unitPrice=parseFloat(unitPrice);//数字接收
		//币种数量
		var count = $("[name='count2']").val();
		count=parseFloat(count);//数字接收
		//币种状态
		var type = $('#type2 option:selected').val();
		type = parseInt(type);
		//apiKey
		var apiKey = $("#apiKey2").val();
		//secret
		var secret = $("#secret2").val();
		$.ajax({
	        type: "get",
	        url: "/app/exchangeRate/coinlis",
	        data:{coinName:name,unitPrice:unitPrice,count:count,status:2,type:type,mid:mid,apiKey:apiKey,secret:secret},
	        dataType: "json",
	        success: function(data){
	        	window.location.reload();
	        }
	    });
	});
});